package action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import pageModel.Inventory;
import pageModel.Json;
import service.InventoryServiceI;

import com.opensymphony.xwork2.ModelDriven;
@Namespace("/")
@Action(value="inventoryAction")
public class InventoryAction extends BaseAction implements ModelDriven<Inventory>{
Inventory inventory = new Inventory();
private InventoryServiceI inventoryService;

	public InventoryServiceI getInventoryService() {
	return inventoryService;
}
@Autowired
public void setInventoryService(InventoryServiceI inventoryService) {
	this.inventoryService = inventoryService;
}
	@Override
	public Inventory getModel() {
		return inventory;
	}
	public void datagrid(){
		super.writeJson(inventoryService.datagrid(inventory));
	}
	public void editor(){
		Json j=new Json();
		try{
		inventoryService.edit(inventory);
		j.setSuccess(true);
		j.setMsg("编辑成功!");
	  }catch(Exception e){
		j.setMsg("编辑失败!"); 
	  }
		super.writeJson(j);
	}
}
